import { Provide, Inject } from '@midwayjs/core';
import { DepartmentDao } from '../dao/departmentDao';
import { Context } from '@midwayjs/koa';
import { BigIntService } from './bigInt.service';
import { PageDTO } from '../dto/page';
import {
  DepartmentDTO,
  NewDirectorIdDTO,
  UpdateDepartmentDTO,
} from '../dto/department';

@Provide()
export class DepartmentService {
  @Inject()
  ctx: Context;
  @Inject()
  departmentDao: DepartmentDao;
  @Inject()
  bigIntService: BigIntService;
  //获取所有部门信息
  async getDepartments() {
    return await this.departmentDao.getDepartments();
  }
  //查找科室
  async findDepartment(field: string, value: string) {
    return await this.departmentDao.findDepartment(field, value);
  }
  //查找该科室是否存在该用户
  async findDepartmentMember(userId: string, departmentId: string) {
    return await this.departmentDao.findDepartmentMember(userId, departmentId);
  }
  //添加科室
  async addDepartment(departmentName: DepartmentDTO['departmentName']) {
    return await this.departmentDao.addDepartment(departmentName);
  }
  //获取我的科室信息
  async getMyDepartment(departmentId: string, pageDto: PageDTO) {
    return await this.departmentDao.getMyDepartment(departmentId, pageDto);
  }
  //退出科室
  async exitDepartment(userId: string, departmentId: string) {
    return await this.departmentDao.exitDepartment(userId, departmentId);
  }
  //解散科室
  async delDepartment() {
    return await this.departmentDao.delDepartment();
  }
  //主任转移权限
  async replaceDirector(
    newDirectorIdDto: NewDirectorIdDTO,
    departmentId: string
  ) {
    return await this.departmentDao.replaceDirector(
      newDirectorIdDto,
      departmentId
    );
  }
  //管理员获取所有科室信息
  async getAdminDepartments(pageDto: PageDTO) {
    return await this.departmentDao.getAdminDepartments(pageDto);
  }
  //管理员查找科室成员
  async getDepartmentMember(departmentId: string) {
    return await this.departmentDao.getDepartmentMember(departmentId);
  }
  //修改科室信息
  async updateDepartment(updateDepartmentDto: UpdateDepartmentDTO) {
    return await this.departmentDao.updateDepartment(updateDepartmentDto);
  }
  //管理员设置科室主任
  async adminSetDirector(userId: string, departmentId: string) {
    return await this.departmentDao.adminSetDirector(userId, departmentId);
  }
}
